-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add convenience methods to StringScanner
#16595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add convenience methods to StringScanner
#16595
Conversation
|
I think the spec failure here is a flapper, it is a TCP error unrelated to the change. |
81b7096 to
c046758
Compare
…s only an issue for nonzero indices
|
Updated docs. Also realized there's a subtle footgun with |
|
And yeah having played around with it for a bit, I think this is a tricky enough issue to warrant removing |
StringScanner
Depends on #16557.Extracted from #16455.
Fixes #11259, with the exception of the methods that mutate the string.
Rationale
Ruby's comparable StringScanner library provides a number of extra convenience methods. I've gone through the list and implemented/specced the ones that make sense here.
Changes
#matched? : Boolto check for the presence of@last_match#current_char : Char,#previous_char : Charas well as nilable variants#current_byte : UInt8,#previous_byte : UInt8, as well as nilable variants#beginning_of_line?I believe originally conceived because anchors like^were non-functional in Ruby due to a bug in their implementation - not an issue in Crystal. It is generally a useful method though, and I couldn't see an argument against including it.#rewind(Int)to move the scan head backwards manuallyRemoved as this has some deep issues in its interactions with#unscanfor rewinding to the start of the previous scan#checkand#scan_until. Will open a separate PR for it later.